// AWTCanvas.cpp: implementation of the AWTCanvas class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "AWTTest.h"
#include "AWTCanvas.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(AWTCanvas, AWTComponent)

AWTCanvas::AWTCanvas()
{
	m_clipboardListener = NULL;
}

AWTCanvas::~AWTCanvas()
{
	if (m_clipboardListener != NULL)
	{
		if (m_clipboardListener->isMultiCaster())
		{
#ifdef UNDER_CE
			AWTEventMulticaster* mc = (AWTEventMulticaster*)m_clipboardListener;
#else
			AWTEventMulticaster* mc = dynamic_cast<AWTEventMulticaster*>(m_clipboardListener);
#endif
			delete mc;
		}
	}
}

void AWTCanvas::paint(CDC* pDC)
{
}

CWnd* AWTCanvas::createComponent()
{
	CWnd* wParent = getParent()->getPeer();
	if (wParent == NULL)
		return wParent;
	CWnd* pwnd = new AWTCanvasPeer(this);
	CWnd* wndParent = getParent()->getPeer();
	if (wndParent == NULL)
		return NULL;
	pwnd->Create(NULL, _T(""), WS_CHILD | WS_VISIBLE, getBounds(), wParent, 0);
	pwnd->SetFont(CFont::FromHandle(m_font));
	if (!m_enabled)
		pwnd->EnableWindow(FALSE);
	return pwnd;
}

void AWTCanvas::processClipboardEvent(AWTClipboardEvent* e)
{
	if (m_clipboardListener != NULL) 
	{
    int id = e->getId();
    switch(id) 
		{
      case AWTClipboardEvent::CLIPBOARD_CUT:
        m_clipboardListener->cut(e);
        break;
      case AWTClipboardEvent::CLIPBOARD_COPY:
        m_clipboardListener->copy(e);
        break;
      case AWTClipboardEvent::CLIPBOARD_PASTE:
        m_clipboardListener->paste(e);
        break;
		}
  }
}
